#!/bin/bash

echo "Creating all skeleton tests..."

rm -rf Tests-Skeleton
mkdir  Tests-Skeleton

find ../front-framework/lib -name '*.php' -print | egrep -v 'frontstart|bootstrap' |
perl -e '
while (<>) {
    chomp;
    $FILEPATH = $_;
    if ($FILEPATH =~ m!front-framework/(lib/)?(.*).php$!) {
        $CLASS = $2;
        $CLASS =~ s!/!\\\\!;
        $CLASS =~ s!/!!g;
        $TESTCLASS = "${CLASS}Test";
        $TESTCLASS =~ s!\\+!!g;
        $TESTCLASSFILE = "Tests-Skeleton/$TESTCLASS.php";
        print "$FILEPATH $CLASS $TESTCLASS $TESTCLASSFILE\n";
    }
}
' |
while read FILEPATH CLASS TESTCLASS TESTCLASSFILE
do
    echo phpunit-skelgen --bootstrap frontstart.inc.php --test -- "$CLASS" $FILEPATH $TESTCLASS $TESTCLASSFILE
    phpunit-skelgen --bootstrap frontstart.inc.php --test -- "$CLASS" $FILEPATH $TESTCLASS $TESTCLASSFILE
    if [ ! -f "Tests-Code/$TESTCLASS.php" ]
    then
        # cp $TESTCLASSFILE "Tests-Code/$TESTCLASS.php"
        # echo "$TESTCLASS: Created new skeleton file Tests-Code/$TESTCLASS.php"
        echo "$TESTCLASS: Created new skeleton file which does not exist in Tests-Code ($TESTCLASSFILE)"
    fi
done
echo "Creating all skeleton tests... Complete."

exit

PHPUnit Skeleton Generator 1.2.1 by Sebastian Bergmann.

Usage: phpunit-skelgen --class ClassTest
       phpunit-skelgen --class -- ClassTest [ClassTest.php] [Class] [Class.php]
       phpunit-skelgen --test Class [Class.php] [ClassTest] [ClassTest.php]
       phpunit-skelgen --test -- Class [Class.php] [ClassTest] [ClassTest.php]

  --class             Generate Class [in Class.php] based on ClassTest [in ClassTest.php]
  --test              Generate ClassTest [in ClassTest.php] based on Class [in Class.php]

  --bootstrap <file>  A "bootstrap" PHP file that is run at startup

  --help              Print this usage information
  --version           Print the version
